<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>

    <!--引入高德地图-->
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
    <script type="text/javascript"
            src="https://webapi.amap.com/maps?v=1.4.15&key=38ec219a062bbf92f1f3ccd9a574752b"></script>

    <style>

        #container {
            width: 100%;
            height: 410px;
        }

        .amap-icon img,
        .amap-marker-content img {
            width: 17px;
            height: 25px;
        }

    </style>

</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>首页
            <small>公司分布图</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>公司分布图</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <el-tabs v-model="activeName" @tab-click="handleClick">
                <el-tab-pane label="分布图" name="first">
                    <div id="container"></div>
                </el-tab-pane>
                <el-tab-pane label="详细信息" name="second">
                    <div class="filter-container">
                        <el-input placeholder="公司地址" v-model="pagination.queryString" style="width: 200px;"
                                  class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="findPage(1)" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新增地址</el-button>

                    </div>

                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="address" label="公司地址" align="center"></el-table-column>
                        <el-table-column prop="longitude" label="所在经度" align="center"></el-table-column>
                        <el-table-column prop="latitude" label="所在纬度" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>

                    <div class="pagination-container">
                        <el-pagination
                                class="pagiantion"
                                @current-change="handleCurrentChange"
                                :current-page="pagination.currentPage"
                                :page-size="pagination.pageSize"
                                layout="total, prev, pager, next, jumper"
                                :total="pagination.total">
                        </el-pagination>
                    </div>

                </el-tab-pane>
            </el-tabs>
        </div>
    </div>
</div>
</body>


<script>
    var vue = new Vue({
        el: '#app',
        data: {
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 0,
                queryString: null,
            },
            dataList: [],//列表数据
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            company: {
                id: "",
                address: "",
                latitude: "",
                longitude: "",
            },
        },
        created() {
            this.findPage();
        },

        mounted() {
            this.initMap();
        },

        methods: {

            //创建和初始化地图函数：
            initMap() {
                var map = new AMap.Map("container", {
                    resizeEnable: true,
                    zoom: 10,
                    center: [114.400307, 30.707596],//中心点坐标
                });

                axios.post("/company/findAll.do")
                    .then((resp) => {
                        if (resp.data.flag) {
                            this.company = resp.data.data;
                            for (var i = 0; i < resp.data.data.length; i++) {
                                marker = new AMap.Marker({
                                    icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-red.png",
                                    position: [this.company[i].longitude, this.company[i].latitude],
                                    label: {
                                        offset: new AMap.Pixel(-35, -35),  //设置文本标注偏移量
                                        content: "<font style='font-size: 120%'>" + this.company[i].address + "</font>", //设置文本标注内容
                                        direction: 'right' //设置文本标注方位
                                    }
                                });
                                marker.setMap(map);
                            }
                        }
                    })
            },

            // 弹出添加窗口
            handleCreate() {
                window.location.href = 'add-address.html';
            },

            //分页查询
            findPage(page) {
                if (page != undefined) {
                    this.pagination.currentPage = page;
                }
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                axios.post("/company/findPage.do", param)
                    .then((resp) => {
                        this.dataList = resp.data.rows;
                        this.pagination.total = resp.data.total;
                    })
            },

            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },

            // 删除
            handleDelete(row) {
                this.$confirm("确认删除吗？", "提示", {type: 'warning'})
                    .then(() => {
                        axios.get("/company/delete.do?id=" + row.id)
                            .then((resp) => {
                                if (resp.data.flag) {
                                    this.$message({
                                        message: resp.data.message,
                                        type: "success"
                                    });
                                    this.findPage();
                                } else {
                                    this.$message.error(resp.data.message);
                                }
                            });
                    })
                    .catch(() => {
                        this.$message({
                            message: "操作已取消",
                            type: "info"
                        });
                    });
            }
        }
    })
</script>
</html>
